<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
<meta name="renderer" content="webkit"/>
<meta name="force-rendering" content="webkit"/>
<title></title>
  <#include "../style.ftl" />
</head>
<body>
<div class="headerbox">
  <div class="header">
    <div class="headerL">
      <a onclick="javascript:history.back(-1)" class="goback"><img src="${staticPath}front/images/goback.png" /></a>
    </div>
    <div class="headerC">
      <p>添加收货地址</p>
    </div>
    <div class="headerR">
       <a href="javascript:saveAddress()">完成</a>
    </div>
  </div>
</div>
<div class="clear"></div>
<div class="hbox"></div>
<div class="kbox"></div>
<form action="#" id="dbForm">
<div class="addressDiv">
  <div class="addiv1">
    <input type="hidden" name="addressId" value="${params.addressId!}"/>
    <div class="addiv1_l">收货人：</div>
    <div class="addiv1_r"><input name="realName" type="text" value="${memberAddress.realName!}"/></div>
  </div>
  <div class="addiv1">
    <div class="addiv1_l">手机号：</div>
    <div class="addiv1_r"><input name="mobile" type="text" VALUE="${memberAddress.mobile!}"/></div>
  </div>
  <div class="addiv1">
    <div class="addiv1_l">省市区：</div>
    <div class="addiv1_c">
      <select name="provinceId" onchange="selectProvince(this.value)">
        <option value="">请选择省份</option>
        <#list provinceList as province>
          <option value="${province.id!}" <#if memberAddress?? && province.id==memberAddress.provinceId>selected</#if>>${province.name!}</option>
        </#list>
        <option>请选择城市</option>
      </select>
    </div>
  </div>
  <div class="addiv1">
    <div class="addiv1_l">城市：</div>
    <div class="addiv1_c">
      <select name="citycode" id="citycode">
        <option value="">请选择城市</option>
      </select>
    </div>
  </div>
  <div class="addiv1">
    <div class="addiv1_l">详细地址：</div>
    <div class="addiv1_r"><input name="address" type="text" value="${memberAddress.address!}"/></div>
  </div>
</div>
</form>
<div class="clear"></div>
<div class="kbox"></div>
</body>
<script>
  function selectProvince(id){
    jQuery.post("${basePath}cityList", {'provinceId':id},function(result){
      if(result.success){
        $("#citycode").empty();
        $("#citycode").append(`<option value="">请选择城市</option>`);
        result.data.forEach(function(item){
          $("#citycode").append(`<option value="`+item.cityCode+`">`+item.name+`</option>`);
        });
      }else {
      }
    });
  }
  <#if memberAddress??>
  selectProvince("${memberAddress.provinceId!}");
  setTimeout(function(){
    $("#citycode").val('${memberAddress.citycode}');
  },1000)
  </#if>

  function saveAddress(){
    jQuery.post("${basePath}home/express/address/save", $("#dbForm").serializeArray(),function(result){
      if(result.success){
        location.href="${basePath}home/express/address/list?cartIds=${params.cartIds!}&skuId=${params.productId!}&qty=${params.qty!}"
      }else {
        alert(result.msg);
      }
    });
  }

</script>
</html>
